#include "rectsubclass.h"
#include <QGraphicsSceneMouseEvent>

qreal ap,bp,a,b;

rectSubClass::rectSubClass()
{
    this->index=99999;
    this->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
    const qreal length=10;
    this->setRect(-length/2.0,-length/2.0,length,length);
}

rectSubClass::rectSubClass(int no)
{

    this->index=no;
    this->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
    const qreal length=10;
    this->setRect(-length/2.0,-length/2.0,length,length);
}

rectSubClass::rectSubClass(int no, int pathType)
{
    this->index=no;
    this->myParentPathType=pathType;
    this->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
    const qreal length=10;
    this->setRect(-length/2.0,-length/2.0,length,length);
}

rectSubClass::rectSubClass(int no, int pathNo, int pathType)
{
    this->index=no;
    this->myParentPathNo=pathNo;
    this->myParentPathType=pathType;
    if(pathType == 1)
        this->setPen(QPen(QColor(Qt::red)));
    else if(pathType == 2)
        this->setPen(QPen(QColor(Qt::green)));
    else if(pathType == 4)
        this->setPen(QPen(QColor(Qt::magenta)));
    this->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
    const qreal length=10;
    this->setRect(-length/2.0,-length/2.0,length,length);
}

int rectSubClass::getMyParentPathType()
{
    return this->myParentPathType;
}

int rectSubClass::getMyParentPathNo()
{
    return this->myParentPathNo;
}

void rectSubClass::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    if(Qt::LeftButton == event->button())
    {
        ap=event->pos().x();
        bp=event->pos().y();
        emit abce_moved(this->index);
    }
}

void rectSubClass::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if(event->buttons() & Qt::LeftButton)
    {

        a=event->pos().x();
        b=event->pos().y();
        int c=this->index;
        int d=this->myParentPathNo;
        int e=this->myParentPathType;
        //QPointF myPos=this->pos();
        emit abcd_xyz_moved(a,b,c,d,e);
    }
}

void rectSubClass::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{

}

